<!DOCTYPE html>
<html style="height: 100%;">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0,
		minimum-scale=1.0, maximum-scale=1.0"/>
    <meta name="format-detection" content="telephone=no"> <!--禁用IOS手机页面数字自动识别为手机号-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <title style="align-content: center">
        紫燕燃动世界杯
    </title>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <script type="text/javascript" src="/js/jquery.min.js" ></script>
    <script src="/js/layer/layer.js"></script>
    <script src="/js/rem.js"></script>
    <link rel="stylesheet" href="/css/base.css">
    <link rel="stylesheet" href="/css/menufoot.css?v=3">
</head>
<body style="height: 100%;margin: 0;padding: 0;overflow: hidden;">
<audio id="ziyan_music" autoplay="autoplay" controls="controls" loop="loop" style="display: none;" preload="auto" src="http://ziyan-image.oss-cn-hangzhou.aliyuncs.com/guoqi/ziyan.mp3"></audio>
<iframe src="/index/home" id="iframe_con" scrolling="yes" frameborder="0" width="100%" height="100%" style="display:block;border:0px;*width: 100%;width: 100%;"></iframe>

<div class="audio-btn" rel="1" onclick="playMusic(this)"></div>

<div class="loading_div_tt" id="loading_div_tt">
    <img src="/img/alert/loading_tt.png">
</div>
<div class="zhezao share_zhezhao">
    <div class="share">
        <div class="msg" id="message">好球！分享成功！</div>
        <div class="mp">
            <p class="msg1">您今天又获得一次竞猜机会</p>
            <p class="msg2">继续参赛赢大奖吧！</p>
        </div>
        <div class="url_btn">
            <a href="javascript:;" onclick="urlTo()"></a>
        </div>
    </div>
</div>

<div class="guess_op_div" id="guess_div_error_tt">
    <div class="guess_kuang_error">
        <div class="tip_close"></div>
        <div class="tip_content">
            <span class="tip_title" id="error_msg">今日获得竞猜机会已达上限！</span>
        </div>
        <div class="tip_tip" id="error_tip">
            点击微信屏幕右上角<img src="http://ziyan-image.oss-cn-hangzhou.aliyuncs.com/front/alert/fen.png">分享好友继续燃动世界杯
        </div>
    </div>
</div>

<div class="bao-zhezao" style="display: <?php echo $this->res['pid'] == 0 ? 'none' : 'block'?>">
    <div class="jp jingpin<?php echo $this->res['pid']?>">
        <div class="guanbi"></div>
        <div class="lingqu"></div>
        <input type="hidden" id="rank_id" value="<?php echo $this->res['rank_id']?>">
    </div>
</div>
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
    $(".tip_close").on('click',function () {
        $("#guess_div_error_tt").hide();
        document.getElementById('iframe_con').contentWindow.location.reload(true);
    });
    function playMusic(el) {
        var rel = $(el).attr('rel');
        if(rel == 1){
            //关闭音乐
            audioAutoStop('ziyan_music');
            $(el).attr('rel',0);
            $(".audio-btn").css('background-position','-0.75rem');
        }else{
            //打开音乐
            audioAutoPlay('ziyan_music');
            $(el).attr('rel',1);
            $(".audio-btn").css('background-position','0');
        }
    }
    //查看奖品
    $('.lingqu').on('click',function () {
        var id = $("#rank_id").val();
        $.ajax({
            url  : '/index/update-user-rank',
            type : 'post',
            data : {id:id},
            dataType : 'json',
            success : function (res) {
                $('.bao-zhezao').hide();
                show_loading();
                document.getElementById('iframe_con').contentWindow.location.href = '/my/winning';
                setTimeout('close_locading()',500);

            },error:function (res) {
                document.getElementById('iframe_con').contentWindow.location.reload(true);
            }
        });
    });

    $('.guanbi').on('click',function () {
        var id = $("#rank_id").val();
        $.ajax({
            url  : '/index/update-user-rank',
            type : 'post',
            data : {id:id},
            dataType : 'json',
            success : function (res) {
               $('.bao-zhezao').hide();
                document.getElementById('iframe_con').contentWindow.location.reload(true);
            },error:function (res) {
                document.getElementById('iframe_con').contentWindow.location.reload(true);
            }
        });

    });
    function urlTo() {
        $(".share_zhezhao").hide();
        show_loading();
        document.getElementById('iframe_con').contentWindow.location.reload(true);
        setTimeout('close_locading()',500);
    }
    function show_loading() {
        $("#loading_div_tt").show();
    }
    function close_locading() {
        $("#loading_div_tt").hide();
    }
    function audioAutoPlay(id){
        var audio = document.getElementById(id),
            play = function(){
                audio.play();
                document.removeEventListener("touchstart",play, false);
            };
        audio.play();
        document.addEventListener("WeixinJSBridgeReady", function () {
            play();
        }, false);
        document.addEventListener('YixinJSBridgeReady', function() {
            play();
        }, false);
        document.addEventListener("touchstart",play, false);
    }
    function audioAutoStop(id){
        var audio = document.getElementById(id),
            pause = function(){
                audio.pause();
                document.removeEventListener("touchstart",pause, false);
            };
        audio.pause();
        document.addEventListener("WeixinJSBridgeReady", function () {
            pause();
        }, false);
        document.addEventListener('YixinJSBridgeReady', function() {
            pause();
        }, false);
        document.addEventListener("touchstart",pause, false);
    }
    audioAutoPlay('ziyan_music');
</script>
<script>
    $(function() {
        wxStart();
    });
    var title = '<?php echo $this->result['title'] ?>';
    var url = '<?php echo $this->result['url'] ?>';
    function wxStart(){
        var appId = '<?php echo \Util\Config::get('weixin_appid','Env');?>';
        var timestamp = '<?php echo $this->result['timestamp'] ?>';
        var nonceStr = '<?php echo $this->result['wxnonceStr'] ?>';
        var signature = '<?php echo $this->result['wxSha1'] ?>';
        var image =  'http://'+'<?php echo \Util\Config::get('weixin_domain', 'Env')?>'+'/img/alert/share_fen.jpg';
        wx.config({
            debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
            appId: appId, // 必填，公众号的唯一标识
            timestamp: timestamp, // 必填，生成签名的时间戳
            nonceStr: nonceStr, // 必填，生成签名的随机串
            signature: signature,// 必填，签名，见附录1
            jsApiList: [
                'onMenuShareTimeline',
                'onMenuShareAppMessage',
                'onMenuShareQQ',
                'checkJsApi',
                'onMenuShareWeibo'
            ] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
        });
        wx.ready(function(){
            wx.onMenuShareTimeline({//分享朋友圈
                title: title, // 分享标题
                desc: '#紫燕燃动世界杯#', // 分享描述
                link: url, // 分享链接
                imgUrl: image, // 分享图标
                trigger: function (res) {

                },
                success: function (res) {
                    // 用户确认分享后执行的回调函数
                    addShareLog('2');
                },
                cancel: function (res) {
                    layer.msg('已取消');
                    // 用户取消分享后执行的回调函数
                },
                fail: function (res) {
                    layer.msg('wx.onMenuShareTimeline:fail: ' + JSON.stringify(res));
                }
            });

            wx.onMenuShareAppMessage({//分享给朋友
                title: title, // 分享标题
                desc: '#紫燕燃动世界杯#', // 分享描述
                link: url, // 分享链接
                imgUrl: image, // 分享图标
                type: 'link', // 分享类型,music、video或link，不填默认为link
                dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                trigger: function (res) {
                },
                success: function (res) {
                    // 用户确认分享后执行的回调函数
                    addShareLog('1');
                },
                cancel: function () {
                    // 用户取消分享后执行的回调函数
                }
            });
        });
    }
    $(".share_cha").click(function () {
        document.getElementById('iframe_con').contentWindow.location.reload(true);
        $('.share_zhezhao').hide();
    });
    /**
     * 分享成功之后插入一条分享记录
     */
    function addShareLog($share_goals) {
        $.ajax({
            url:"/common/add-share-log",
            type:"post",
            dataType : 'json',
            contentType: "application/json",
            async:false, //ajax 内部嵌套ajax  使用同步请求，不能异步,否则会出错，不要轻易修改
            data : {
                share_goals: $share_goals,
                title: title,
                link: url
            },
            success:function(data) {
                if(parseInt(data.result) <= 3){
                    $('.share_zhezhao').show();
                    $("#guess_div_error_tt").hide();

                    document.addEventListener('touchmove',function (event) {
                        event.preventDefault();
                        window.event.returnValue=false;
                    },false);
                }else{
                    $('.share_zhezhao').hide();
                    $("#guess_div_error_tt").hide();
                    document.addEventListener('touchmove',function (event) {
                        window.event.returnValue=true;
                    },false);
                }
            },
            error:function (data) {
                layer.msg('分享失败',function() {
                    window.location.reload();
                });
            }
        });
    }
</script>
</body>
</html>
